/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.musiclibrary.backend.services;

import cz.muni.fi.pa165.musiclibrary.api.dao.AuthorDAO;
import cz.muni.fi.pa165.musiclibrary.api.dto.AuthorDTO;
import cz.muni.fi.pa165.musiclibrary.api.entities.Author;
import cz.muni.fi.pa165.musiclibrary.api.transfers.AuthorT;
import cz.muni.fi.pa165.musiclibrary.api.services.AuthorService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Dominik
 */
@Service
@Transactional
public class AuthorServiceImpl implements AuthorService {

    private AuthorDAO authorDAO;
    
    public void setAuthorDAO(AuthorDAO authorDAO) {
        this.authorDAO = authorDAO;
    }
    
    public void createAuthor(AuthorDTO author) {
        authorDAO.createAuthor(AuthorT.DTOtoAuthor(author));
    }

    public AuthorDTO getAuthor(Long id) {
        return AuthorT.AuthorToDTO(authorDAO.getAuthor(id));
    }

    public List<AuthorDTO> getAllAuthors() {
        List<AuthorDTO> allAuthorsDTO = new ArrayList();
        List<Author> allAuthors = authorDAO.getAllAuthors();
        for(Author author : allAuthors) {
            allAuthorsDTO.add(AuthorT.AuthorToDTO(author));
        }
        return allAuthorsDTO;
    }

    public void updateAuthor(AuthorDTO author) {
        authorDAO.updateAuthor(AuthorT.DTOtoAuthor(author));
    }

    public void deleteAuthor(AuthorDTO author) {
        authorDAO.deleteAuthor(AuthorT.DTOtoAuthor(author));
    }
    
}
